class Solution {
public:
    //二分查找
    int takeAttendance(vector<int>& records) 
    {
        int left = 0, right = records.size() - 1;
        while(left < right)
        {
            int mid = left + (right - left) / 2;
            if(records[mid] == mid)
                left = mid + 1;
            else
                right = mid;
        }
        if(records[left] == left)
            return left + 1;
        else 
            return left;
    }
};

class Solution {
public:
    //直接遍历
    int takeAttendance(vector<int>& records) 
    {
        int n = records.size();
        int i = 0;
        for(; i < n; i++)
        {
            if(records[i] != i)
                return i;
        }

        return i;
    }
};

class Solution {
public:
    //哈希
    int takeAttendance(vector<int>& records) 
    {
        int n = records.size();
        set<int> hash;
        int i = 0;
        for(; i < n; i++)
        {
           hash.insert(records[i]);
        }
        for(i = 0; i < n; i++)
        {
            if(hash.count(i) != 1)
                return i;
        }
        return i;
    }
};

class Solution {
public:
    //位运算
    int takeAttendance(vector<int>& records) 
    {
        int res = 0;
        for(int i = 0; i < records.size(); i++)
        {
            res ^= records[i];
        }
        for(int i = 0; i <= records.size(); i++)
        {
            res ^= i;
        }
        return res;
    }
};

class Solution {
public:
    //高斯求和
    int takeAttendance(vector<int>& records) 
    {
        int sum = 0, sumarr = 0;
        for(int i = 0; i <= records.size(); i++)
        {
            sum += i;
            if(i < records.size()) 
                sumarr += records[i];
        }
        return sum - sumarr;
    }
};

#include <iostream>
#include <vector>
using namespace std;

int main() 
{
    int n, q;
    cin >> n >> q;

    vector<int> arr(n + 1);
    //写数据
    for(int i = 1; i <= n; i++)
    {
        cin >> arr[i];
    }

    //定义前缀和数组
    vector<long long> dp(n + 1);//防溢出

    for(int i = 1; i <= n; i++)
    {
        dp[i] = dp[i - 1] + arr[i];
    }
    
    while(q--)
    {
        int l,r;
        cin >> l >> r;
        cout << dp[r] - dp[l - 1] << endl;
    }

    return 0;
}
